/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.screen;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.sql.SQLException;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import org.ini4j.Ini;
import org.ini4j.Wini;
import sys.bean.ClienteBean;
import sys.bean.EmpresaBean;
import sys.bean.ProdutoRomaneioBean;
import sys.bean.RomaneioBean;
import sys.bean.StatusBean;
import sys.bean.StatusRomaneioBean;
import sys.dao.CidadeDao;
import sys.dao.ClienteDao;
import sys.dao.EmpresaDao;
import sys.dao.EstadoDao;
import sys.dao.MotoristaDao;
import sys.dao.ProdutoPedidoDao;
import sys.dao.ProdutoRomaneioDao;
import sys.dao.RomaneioDao;
import sys.dao.StatusDao;
import sys.dao.StatusRomaneioDao;
import sys.dao.VeiculoDao;
import sys.utils.LetterUpper;
import sys.utils.Mensagens;
import sys.utils.Singleton;
import static sys.utils.Utils.dirFileTraco;

/**
 *
 * @author Administrador
 */
public class CCarregarPedido extends javax.swing.JDialog {

    private CPedidosParaEntrega paiPedidosParaEntrega;
    private boolean inserir;

    /*
     tela 0 - Tela de cadastro de traços
     tela 1 - Tela para alteração de traços
     */
    public int tela = 0;

    PrintService ps[];
    PrintService impressora;

    Ini ini = null;
    Wini wini = null;

    NumberFormat formatoMoeda = NumberFormat.getCurrencyInstance();
    SimpleDateFormat formDataBr = new SimpleDateFormat("dd/MM/yyyy");

    ClienteBean cliente;
    EmpresaBean empresa;
    RomaneioBean romaneio;

    private List<StatusBean> listaStatus;
    private List<ProdutoRomaneioBean> listaSerEntregue = new ArrayList<>();

    StatusRomaneioDao daoStatusRomaneio = new StatusRomaneioDao();
    StatusDao daoStatus = new StatusDao();
    CidadeDao daoCidade = new CidadeDao();
    EstadoDao daoEstado = new EstadoDao();
    MotoristaDao daoMotorista = new MotoristaDao();
    VeiculoDao daoVeiculo = new VeiculoDao();
    ClienteDao daoCliente = new ClienteDao();
    ProdutoPedidoDao daoProdutoPedido = new ProdutoPedidoDao();
    EmpresaDao daoEmpresa = new EmpresaDao();
    RomaneioDao daoRomaneio = new RomaneioDao();
    ProdutoRomaneioDao daoProdutoRomaneio = new ProdutoRomaneioDao();

    Double tracoPedra;
    Double tracoPedrisco;
    Double tracoAreia;
    Double tracoCimento;
    Double tracoAditivo;
    Double tracoAgua;

    public CCarregarPedido(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        paiPedidosParaEntrega = (CPedidosParaEntrega) parent;
        initComponents();
        setLocationRelativeTo(null);
        carregaDadosMaquinaLocal();
        detectarImpressoras();
    }

    public String formatoMoeda(double valor) {
        return formatoMoeda.format(valor).replace("R$", "");
    }

    private void detectarImpressoras() {
        try {
            jbImpressora.removeAllItems();
            DocFlavor df = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
            ps = PrintServiceLookup.lookupPrintServices(df, null);
            int pos = 0;
            int cont = 0;
            for (PrintService p : ps) {
                jbImpressora.addItem(p.getName());
                if (p.getName().equals("BEMA")) {
                    pos = cont;
                }
                cont++;
            }
            jbImpressora.setSelectedIndex(pos);
        } catch (Exception e) {
            Mensagens.msgErro("Erro Ao Encontrar Impressoras\n" + e.getMessage());
        }
    }

    private void imprimir() {
        for (int i = 0; i < 1; i++) {
            // Conteúdo a ser impresso '\u039A' utilizado para cortar o papel
            InputStream stream = new ByteArrayInputStream((gerarImpressao()).getBytes());
            impressora = ps[jbImpressora.getSelectedIndex()];
            DocPrintJob dpj = impressora.createPrintJob();
            // Definição de atributos do conteúdo a ser impresso:  
            DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
            // Cria um Doc para impressão a partir do arquivo exemplo.txt 
            Doc documentoTexto = new SimpleDoc(stream, flavor, null);
            try {
                //  Imprime o documento sem exibir uma tela de dialogo 
                dpj.print(documentoTexto, null);
            } catch (PrintException ex) {
                Mensagens.msgErro("erro ao imprimir, certifique-se de que a impressora foi selecionada corretamente!\n" + ex);
            }
        }
    }

    public void preencheCampos(int idRomaneio) {
        try {
            romaneio = daoRomaneio.getRomaneio(idRomaneio);

            txNRomaneio.setText(romaneio.getIdRomaneio() + "");
            txDataRomaneio.setText(formDataBr.format(romaneio.getDataRomaneio()));
            txCodigoCliente.setText(romaneio.getCliente().getCodigo());
            txNomeCliente.setText(romaneio.getCliente().getNome());
            dataEntregaAgendada.setText(formDataBr.format(romaneio.getDataEntregaAgendada()));
            txHoraAgendado.setText(romaneio.getHoraAgendada());
            txEndereco.setText(romaneio.getEnderecoEntrega());
            txNEndereco.setText(romaneio.getnEnderecoEntrega());
            txBairro.setText(romaneio.getBairroEntrega());

            cbEstado.getModel().setSelectedItem(romaneio.getCidade().getEstado().getNome() + "-" + romaneio.getCidade().getEstado().getUf());
            cbCidade.getModel().setSelectedItem(romaneio.getCidade().getNome() + "-" + romaneio.getCidade().getEstado().getUf());

            cbMotorista.getModel().setSelectedItem(romaneio.getMotorista().getIdMotorista() + " - " + romaneio.getMotorista().getNome() + " " + romaneio.getMotorista().getSobreNome() + " - " + romaneio.getMotorista().getCpf());
            cbVeiculo.getModel().setSelectedItem(romaneio.getVeiculo().getIdVeiculo() + " - " + romaneio.getVeiculo().getModelo() + " - " + romaneio.getVeiculo().getPlaca());

            carregaStatus();
            carregaProdutosRomaneio(idRomaneio);
            txImpressao.setText(gerarImpressao());

        } catch (SQLException ex) {
            Mensagens.msgErro("erro ao carregar romaneio\n" + ex.getMessage());
        }
    }

    private void carregaProdutosRomaneio(int idRomaneio) {
        DefaultTableModel modelo = (DefaultTableModel) tabelaProdutosCliente.getModel();
        modelo.setNumRows(0);
        try {
            listaSerEntregue = daoProdutoRomaneio.produtosRomaneio(idRomaneio);
            for (ProdutoRomaneioBean prodRomaneio : listaSerEntregue) {
                modelo.addRow(new Object[]{
                    prodRomaneio.getProduto().getDescricao(), formatoMoeda(prodRomaneio.getQtdEnviada())
                });
            }
            DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
            centralizado.setHorizontalAlignment(SwingConstants.CENTER);

            tabelaProdutosCliente.getColumnModel().getColumn(1).setCellRenderer(centralizado);

        } catch (SQLException ex) {
            Mensagens.msgErro("erro ao carregar produtos do pedido\n" + ex.getMessage());
        }
    }

    private StatusRomaneioBean retObjetoStatusRomaneio() {

        StatusRomaneioBean statusRomaneio = new StatusRomaneioBean();
        StatusBean status = new StatusBean();

        /*
         pegando status na posição 1
         */
        status.setIdStatus(listaStatus.get(1).getIdStatus());
        statusRomaneio.setStatus(status);

        return statusRomaneio;
    }

    private void carregaStatus() {
        try {
            listaStatus = daoStatus.listaStatus();
            cbStatusAtual.addItem(listaStatus.get(0).getIdStatus() + " - " + listaStatus.get(0).getDescricao());
            cbProximoStatus.addItem(listaStatus.get(1).getIdStatus() + " - " + listaStatus.get(1).getDescricao());
        } catch (SQLException ex) {
            Mensagens.msgErro("erro ao atualizar status\n" + ex.getMessage());
        }
    }

    public final void carregaDadosMaquinaLocal() {
        SimpleDateFormat formatoData = new SimpleDateFormat("EEEE-dd/MMMMM/yyyy");
        try {
            empresa = daoEmpresa.consultaEmpresa();
            lbData.setText(formatoData.format(new Date()));
            lbTerminal.setText(InetAddress.getLocalHost().getHostName() + " / " + InetAddress.getLocalHost().getHostAddress());
            lbUsuario.setText(Singleton.getCodigo() + "-" + Singleton.getNome() + " (" + Singleton.getTipo() + ")");
            lbEmpresa.setText(empresa.getRazaoSocial() + " - " + empresa.getCidade().getNome() + " (" + empresa.getCidade().getEstado().getUf() + ")");
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao carregar dados da maquina local\n" + ex.getMessage());
        }
    }

    private RomaneioBean retObjetoTracos() {
        RomaneioBean r = new RomaneioBean();

        r.setTracoGeradoPedra(tracoPedra);
        r.setTracoGeradoPedrisco(tracoPedrisco);
        r.setTracoGeradoAreia(tracoAreia);
        r.setTracoGeradoCimento(tracoCimento);
        r.setTracoGeradoAditivo(tracoAditivo);
        r.setTracoGeradoAgua(tracoAgua);

        r.setTracoUtilizadiPedra(tracoPedra);
        r.setTracoUtilizadiPedrisco(tracoPedrisco);
        r.setTracoUtilizadiAreia(tracoAreia);
        r.setTracoUtilizadiCimento(tracoCimento);
        r.setTracoUtilizadiAditivo(tracoAditivo);
        r.setTracoUtilizadiAgua(tracoAgua);

        r.setIdRomaneio(Integer.parseInt(txNRomaneio.getText()));

        return r;

    }

    public String gerarImpressao() {
        String impressao = "";

        impressao += " ----------------------------------------------\n";
        impressao += " ----------- VOVO JOAO - CONCRETEIRA  ----------\n";
        impressao += " FONE:(43)3546-2202 - DATA:" + txDataRomaneio.getText() + " ROM.:" + txNRomaneio.getText() + "\n";
        impressao += " ===============================================\n";
        impressao += " USUARIO: " + lbUsuario.getText() + "\n";
        impressao += " ===============================================\n";
        impressao += "          *** ORDEM DE CARREGAMENTO ***        \n";
        impressao += " ===============================================\n";
        impressao += " ============== DADOS DO ROMANEIO ==============\n";
        impressao += " -----------------------------------------------\n";
        impressao += " CLIENTE...: " + txCodigoCliente.getText() + "-" + txNomeCliente.getText() + "\n";
        impressao += " ENDER.....: " + txEndereco.getText() + ", " + txNEndereco.getText() + "\n";
        impressao += " BAIRRO....: " + txBairro.getText() + "\n";
        impressao += " CIDADE....: " + cbCidade.getSelectedItem() + " - ESTADO: " + cbEstado.getSelectedItem() + "\n";
        impressao += " MOTORISTA.: " + cbMotorista.getSelectedItem() + "\n";
        impressao += " VEICULO...: " + cbVeiculo.getSelectedItem() + "\n";
        impressao += " ===============================================\n";
        impressao += " ==============  DADOS DO PRODUTO  =============\n";
        impressao += " ===============================================\n";

        for (ProdutoRomaneioBean prodRomaneio : listaSerEntregue) {
            impressao += " PRODUTO: ";
            impressao += " " + prodRomaneio.getProduto().getDescricao() + "\n";
            impressao += " QTD....:";
            impressao += " " + formatoMoeda(prodRomaneio.getQtdEnviada()) + " " + prodRomaneio.getProduto().getUn() + "\n";
            impressao += " -------------------- TRAÇOS -------------------\n";
            /*
             se tela for 0 esta gerando do arquivo de configuração, senão gera do banco de dados
             */
            if (tela == 0) {
                try {
                    ini = new Ini(new FileInputStream(new File(dirFileTraco())));

                    int codProduto = Integer.parseInt(prodRomaneio.getProduto().getCodigo());

                    tracoPedra = Double.parseDouble(ini.get(codProduto + "", "PEDRA")) * prodRomaneio.getQtdEnviada();
                    tracoPedrisco = Double.parseDouble(ini.get(codProduto + "", "PEDRISCO")) * prodRomaneio.getQtdEnviada();
                    tracoAreia = Double.parseDouble(ini.get(codProduto + "", "AREIA")) * prodRomaneio.getQtdEnviada();
                    tracoCimento = Double.parseDouble(ini.get(codProduto + "", "CIMENTO")) * prodRomaneio.getQtdEnviada();
                    tracoAditivo = Double.parseDouble(ini.get(codProduto + "", "ADITIVO")) * prodRomaneio.getQtdEnviada();
                    tracoAgua = Double.parseDouble(ini.get(codProduto + "", "AGUA")) * prodRomaneio.getQtdEnviada();

                    impressao += " PEDRA...: " + formatoMoeda(tracoPedra) + " KG \n";
                    impressao += " PEDRISCO: " + formatoMoeda(tracoPedrisco) + " KG \n";
                    impressao += " AREIA...: " + formatoMoeda(tracoAreia) + " KG \n";
                    impressao += " CIMENTO.: " + formatoMoeda(tracoCimento) + " KG \n";
                    impressao += " ADITIVO.: " + formatoMoeda(tracoAditivo) + " KG \n";
                    impressao += " AGUA....: " + formatoMoeda(tracoAgua) + " KG \n";
                    impressao += " ===============================================\n\n\n";

                } catch (IOException ex) {
                    Mensagens.msgErro("erro\n" + ex.getMessage());
                }
            } else {
                try {
                    romaneio = daoRomaneio.tracosRomaneio(Integer.parseInt(txNRomaneio.getText()));
                    impressao += " PEDRA...: " + formatoMoeda(romaneio.getTracoUtilizadiPedra()) + " KG \n";
                    impressao += " PEDRISCO: " + formatoMoeda(romaneio.getTracoUtilizadiPedrisco()) + " KG \n";
                    impressao += " AREIA...: " + formatoMoeda(romaneio.getTracoUtilizadiAreia()) + " KG \n";
                    impressao += " CIMENTO.: " + formatoMoeda(romaneio.getTracoUtilizadiCimento()) + " KG \n";
                    impressao += " ADITIVO.: " + formatoMoeda(romaneio.getTracoUtilizadiAditivo()) + " KG \n";
                    impressao += " AGUA....: " + formatoMoeda(romaneio.getTracoUtilizadiAgua()) + " KG \n";
                    impressao += " ===============================================\n\n\n";

                    /*
                     alimentando os valores, pois quando vai alterar carregamento, é necessário ter valor nessas variáveis.
                     */
                    tracoPedra = romaneio.getTracoUtilizadiPedra();
                    tracoPedrisco = romaneio.getTracoUtilizadiPedrisco();
                    tracoAreia = romaneio.getTracoUtilizadiAreia();
                    tracoCimento = romaneio.getTracoUtilizadiCimento();
                    tracoAditivo = romaneio.getTracoUtilizadiAditivo();
                    tracoAgua = romaneio.getTracoUtilizadiAgua();

                } catch (SQLException ex) {
                    Mensagens.msgErro("erro\n" + ex.getMessage());
                }
            }
            impressao += "" + (char) 27 + (char) 109;
        }
        return impressao;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txImpressao = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txNomeCliente = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cbEstado = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        cbCidade = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        txEndereco = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txNEndereco = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txBairro = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txHoraAgendado = new javax.swing.JFormattedTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cbMotorista = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cbVeiculo = new javax.swing.JComboBox();
        txCodigoCliente = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaProdutosCliente = new javax.swing.JTable();
        dataEntregaAgendada = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        btnSalvar = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnImprimir = new javax.swing.JButton();
        btnSair1 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        txNRomaneio = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txDataRomaneio = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jbImpressora = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        lbTerminal = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        lbUsuario = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        lbEmpresa = new javax.swing.JLabel();
        lbData = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel23 = new javax.swing.JLabel();
        cbStatusAtual = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        cbProximoStatus = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CARREGAR PEDIDO");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ORDEM DE CARREGAMENTO:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        txImpressao.setColumns(20);
        txImpressao.setRows(5);
        jScrollPane3.setViewportView(txImpressao);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 466, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DADOS DA ENTREGA:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel2.setText("CÓDIGO:");

        txNomeCliente.setEditable(false);
        txNomeCliente.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txNomeCliente.setForeground(new java.awt.Color(51, 51, 255));

        jLabel9.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel9.setText("ESTADO:");

        cbEstado.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbEstado.setForeground(new java.awt.Color(51, 51, 255));
        cbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<< SELECIONE ESTADO >>" }));
        cbEstado.setEnabled(false);

        jLabel10.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel10.setText("CIDADE:");

        cbCidade.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbCidade.setForeground(new java.awt.Color(51, 51, 255));
        cbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<< SELECIONE CIDADE >>" }));
        cbCidade.setEnabled(false);

        jLabel7.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel7.setText("ENDEREÇO:");

        txEndereco.setDocument(new LetterUpper());
        txEndereco.setEditable(false);
        txEndereco.setBackground(new java.awt.Color(245, 245, 245));
        txEndereco.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txEndereco.setForeground(new java.awt.Color(51, 51, 255));

        jLabel12.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel12.setText("NÚMERO:");

        txNEndereco.setDocument(new LetterUpper());
        txNEndereco.setEditable(false);
        txNEndereco.setBackground(new java.awt.Color(245, 245, 245));
        txNEndereco.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txNEndereco.setForeground(new java.awt.Color(51, 51, 255));
        txNEndereco.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel13.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel13.setText("BAIRRO:");

        txBairro.setDocument(new LetterUpper());
        txBairro.setEditable(false);
        txBairro.setBackground(new java.awt.Color(245, 245, 245));
        txBairro.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txBairro.setForeground(new java.awt.Color(51, 51, 255));

        jLabel14.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel14.setText("PRODUTOS:");

        jLabel6.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel6.setText("DATA DA ENTREGA:");

        txHoraAgendado.setEditable(false);
        txHoraAgendado.setForeground(new java.awt.Color(51, 51, 255));
        try {
            txHoraAgendado.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txHoraAgendado.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txHoraAgendado.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N

        jLabel15.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel15.setText("HORA:");

        jLabel4.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel4.setText("MOTORISTA:");

        cbMotorista.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbMotorista.setForeground(new java.awt.Color(51, 51, 255));
        cbMotorista.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<< SELECIONE MOTORISTA >>" }));
        cbMotorista.setEnabled(false);

        jLabel5.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel5.setText("VEÍCULO:");

        cbVeiculo.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbVeiculo.setForeground(new java.awt.Color(51, 51, 255));
        cbVeiculo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<< SELECIONE VEÍCULO >>" }));
        cbVeiculo.setEnabled(false);

        txNEndereco.setDocument(new LetterUpper());
        txCodigoCliente.setEditable(false);
        txCodigoCliente.setBackground(new java.awt.Color(245, 245, 245));
        txCodigoCliente.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txCodigoCliente.setForeground(new java.awt.Color(51, 51, 255));
        txCodigoCliente.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel8.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel8.setText("NOME:");

        tabelaProdutosCliente.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabelaProdutosCliente.setForeground(new java.awt.Color(0, 0, 255));
        tabelaProdutosCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "PRODUTO", "QTD"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaProdutosCliente.setEnabled(false);
        tabelaProdutosCliente.setGridColor(new java.awt.Color(204, 204, 204));
        tabelaProdutosCliente.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tabelaProdutosCliente);
        if (tabelaProdutosCliente.getColumnModel().getColumnCount() > 0) {
            tabelaProdutosCliente.getColumnModel().getColumn(0).setPreferredWidth(300);
        }

        txNEndereco.setDocument(new LetterUpper());
        dataEntregaAgendada.setEditable(false);
        dataEntregaAgendada.setBackground(new java.awt.Color(245, 245, 245));
        dataEntregaAgendada.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        dataEntregaAgendada.setForeground(new java.awt.Color(51, 51, 255));
        dataEntregaAgendada.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txNEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(202, 202, 202)
                        .addComponent(jLabel10))
                    .addComponent(jLabel14)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(txBairro, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txCodigoCliente)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(24, 24, 24)))
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel8)
                            .addComponent(txNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(dataEntregaAgendada, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(txHoraAgendado)))
                    .addComponent(cbVeiculo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbMotorista, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(jLabel8))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txCodigoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(dataEntregaAgendada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(28, 28, 28)))
                    .addComponent(txHoraAgendado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txBairro, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txNEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbCidade))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbMotorista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel9.setBackground(new java.awt.Color(245, 245, 245));

        btnSalvar.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/salvar.png"))); // NOI18N
        btnSalvar.setText("SALVAR");
        btnSalvar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });
        jPanel9.add(btnSalvar);

        btnAlterar.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/edit.png"))); // NOI18N
        btnAlterar.setText("ALT. TRAÇOS");
        btnAlterar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });
        jPanel9.add(btnAlterar);

        btnImprimir.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        btnImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/print.png"))); // NOI18N
        btnImprimir.setText("IMPRIMIR");
        btnImprimir.setPreferredSize(new java.awt.Dimension(120, 30));
        btnImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirActionPerformed(evt);
            }
        });
        jPanel9.add(btnImprimir);

        btnSair1.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        btnSair1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/delete.png"))); // NOI18N
        btnSair1.setText("SAIR");
        btnSair1.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSair1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSair1ActionPerformed(evt);
            }
        });
        jPanel9.add(btnSair1);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DADOS DO ROMANEIO:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel22.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel22.setText("ROMANEIO:");

        txNRomaneio.setEditable(false);
        txNRomaneio.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txNRomaneio.setForeground(new java.awt.Color(51, 51, 255));
        txNRomaneio.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel11.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel11.setText("DATA ROMANEIO:");

        txDataRomaneio.setEditable(false);
        txDataRomaneio.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txDataRomaneio.setForeground(new java.awt.Color(51, 51, 255));
        txDataRomaneio.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel3.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel3.setText("IMPRESSORA:");

        jbImpressora.setBackground(new java.awt.Color(245, 245, 245));
        jbImpressora.setEditable(true);
        jbImpressora.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jbImpressora.setToolTipText("Certifique-se de ter uma impressora térmica instalada.");
        jbImpressora.setBorder(null);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbImpressora, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel22)
                                    .addComponent(txNRomaneio, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addComponent(txDataRomaneio, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel3))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txNRomaneio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txDataRomaneio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbImpressora)
                .addContainerGap())
        );

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "INFORMAÇÕES:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel17.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/terminal.png"))); // NOI18N

        lbTerminal.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        lbTerminal.setForeground(new java.awt.Color(51, 102, 255));

        jLabel18.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/user.png"))); // NOI18N

        lbUsuario.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        lbUsuario.setForeground(new java.awt.Color(51, 102, 255));

        jLabel19.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/empresa.png"))); // NOI18N

        lbEmpresa.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        lbEmpresa.setForeground(new java.awt.Color(51, 102, 255));

        lbData.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        lbData.setForeground(new java.awt.Color(51, 102, 255));
        lbData.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbTerminal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbEmpresa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(lbTerminal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(9, 9, 9)
                        .addComponent(lbUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(7, 7, 7)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbEmpresa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbData, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "STATUS DO ROMANEIO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel23.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel23.setText("STATUS ATUAL:");

        cbStatusAtual.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbStatusAtual.setForeground(new java.awt.Color(51, 51, 255));
        cbStatusAtual.setEnabled(false);

        jLabel24.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel24.setText("PRÓXIMO STATUS:");

        cbProximoStatus.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbProximoStatus.setForeground(new java.awt.Color(51, 51, 255));
        cbProximoStatus.setEnabled(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbStatusAtual, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel23)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jLabel24, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(cbProximoStatus, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbStatusAtual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbProximoStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
        imprimir();
    }//GEN-LAST:event_btnImprimirActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        if (isInserir()) {
            try {
                daoStatusRomaneio.incluir(retObjetoStatusRomaneio());
                daoRomaneio.atualizaTracos(retObjetoTracos());
                this.paiPedidosParaEntrega.atualizaEntregasAgendadas();
                this.dispose();
            } catch (SQLException ex) {
                Mensagens.msgErro("erro ao incluir romaneio\n" + ex.getMessage());
            }
        } else {
            try {
                daoStatusRomaneio.atualizaHoraCarregamento(listaStatus.get(1).getIdStatus(), Integer.parseInt(txNRomaneio.getText()));
                daoRomaneio.atualizaTracos(retObjetoTracos());
                this.dispose();
            } catch (SQLException ex) {
                Mensagens.msgErro("erro ao atualizar status do carregamento\n" + ex.getMessage());
            }
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnSair1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSair1ActionPerformed
        if (Mensagens.confirmar(this, "deseja realmente sair")) {
            this.dispose();
        }
    }//GEN-LAST:event_btnSair1ActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        CCadastroTracoProduto cTracoProduto = new CCadastroTracoProduto(this, true);
        System.out.println(tracoPedra);
        cTracoProduto.carregaTracos(tracoPedra, tracoPedrisco, tracoAreia, tracoCimento, tracoAditivo, tracoAgua, Integer.parseInt(txNRomaneio.getText()));
        cTracoProduto.setVisible(true);
    }//GEN-LAST:event_btnAlterarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnImprimir;
    private javax.swing.JButton btnSair1;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JComboBox cbCidade;
    private javax.swing.JComboBox cbEstado;
    private javax.swing.JComboBox cbMotorista;
    private javax.swing.JComboBox cbProximoStatus;
    private javax.swing.JComboBox cbStatusAtual;
    private javax.swing.JComboBox cbVeiculo;
    private javax.swing.JTextField dataEntregaAgendada;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JComboBox jbImpressora;
    private javax.swing.JLabel lbData;
    private javax.swing.JLabel lbEmpresa;
    private javax.swing.JLabel lbTerminal;
    private javax.swing.JLabel lbUsuario;
    private javax.swing.JTable tabelaProdutosCliente;
    private javax.swing.JTextField txBairro;
    private javax.swing.JTextField txCodigoCliente;
    private javax.swing.JTextField txDataRomaneio;
    private javax.swing.JTextField txEndereco;
    private javax.swing.JFormattedTextField txHoraAgendado;
    public javax.swing.JTextArea txImpressao;
    private javax.swing.JTextField txNEndereco;
    private javax.swing.JTextField txNRomaneio;
    private javax.swing.JTextField txNomeCliente;
    // End of variables declaration//GEN-END:variables

    public boolean isInserir() {
        return inserir;
    }

    public void setInserir(boolean inserir) {
        this.inserir = inserir;
    }

}
